CREATE TABLE [dbo].[tb_ColaDeMovimientos]
(
[idCola] [int] NOT NULL IDENTITY(1, 1),
[Agente] [int] NULL,
[Fecha] [datetime] NULL,
[Organizacion] [int] NULL,
[Responsable] [int] NULL,
[Fecha1] [datetime] NULL,
[Fecha2] [datetime] NULL,
[SitRev] [int] NULL,
[Nivel] [int] NULL,
[Modalidad] [int] NULL,
[Zona] [int] NULL,
[CargoSalarial] [int] NULL,
[Licencia] [int] NULL,
[CantidadHoras] [int] NULL,
[Estado] [int] NULL,
[Observaciones] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Movimiento] [int] NULL,
[Plaza] [int] NULL,
[FechaTermino] [datetime] NULL,
[CausaAlta] [int] NULL,
[CUISE] [int] NULL,
[ClavePSalarial] [int] NULL,
[Confirmado] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_tb_ColaDeMovimientos_Confirmado] DEFAULT ('N'),
[NormaContinuidad] [int] NULL,
[EstadoCheck] [int] NULL,
[Respuesta] [varchar] (255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[NTUserAutor] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_tb_ColaDeMovimientos_NTUserAutor] DEFAULT (suser_sname()),
[NTUserEjecutor] [varchar] (30) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[FechaEjecucion] [datetime] NULL,
[ChequeoEscuela] [varchar] (1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[NroCertificado] [int] NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[EliminarColayPlazaDeMovimiento] ON [dbo].[tb_ColaDeMovimientos] 
INSTEAD OF DELETE 
AS

DECLARE @IdCola INT 


SELECT @IdCola = IdCola FROM DELETED 

DELETE FROM Tb_PlazasDeMovimiento WHERE IdCola = @IdCola

DELETE FROM Tb_ColaDeMovimientos WHERE IdCola = @IdCola


GO
ALTER TABLE [dbo].[tb_ColaDeMovimientos] ADD CONSTRAINT [PK_tb_ColaDeMovimientos] PRIMARY KEY CLUSTERED  ([idCola]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IDX_Agente] ON [dbo].[tb_ColaDeMovimientos] ([Agente]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [idxtotal] ON [dbo].[tb_ColaDeMovimientos] ([idCola], [Agente], [Fecha], [Organizacion], [Fecha1], [Fecha2], [Estado], [Movimiento]) WITH (FILLFACTOR=90) ON [PRIMARY]
GO
